//
//  EEViewController.m
//  spatialiteLib
//
//  Created by liukai on 11/29/2018.
//  Copyright (c) 2018 liukai. All rights reserved.
//

#import "EEViewController.h"
#include <sqlite3.h>
#include "gaiageo.h"
//#include "spatialite.h"
#import <FMDB/FMDatabase.h>
#import "SpatialView.h"
#import "SpatialiteDataCache.h"
@interface EEViewController ()
@property (nonatomic, strong) SpatialView * spatialView;

@property (nonatomic, strong) NSArray * arrAirports;
@property (nonatomic, strong) NSArray * arrSegments;
@end

@implementation EEViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
    NSString * srcPath = [[NSBundle mainBundle] pathForResource:@"gis" ofType:@"sqlite"];
    NSString * dbPath = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:@"database.db3"];
    
    [[NSFileManager defaultManager] copyItemAtPath:srcPath toPath:dbPath error:nil];
    
    self.spatialView = [[SpatialView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height)];
    [self.view addSubview:self.spatialView];
    
    SpatialiteDataCache * cache = [[SpatialiteDataCache alloc] initWithSpaliteFile:dbPath];
    self.spatialView.cache = cache;
    
    [self.spatialView refresh];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (IBAction)onResetTapped:(id)sender {
    [self.spatialView resetPosition];
}
@end
